package hnair.com.shop.util.storage;

import android.content.SharedPreferences;
import android.preference.PreferenceManager;

import hnair.com.shop.app.Shop;

/**
 * Created by liaowei on 2017/11/17.
 */

public class ShopPreference {

    private static final SharedPreferences PREFERENCES =
            PreferenceManager.getDefaultSharedPreferences(Shop.getApplication());
    private static final String APP_PREFERENCES_KEY = "profile";

    private static SharedPreferences getAppPreferences() {
        return PREFERENCES;
    }

    public static void setAppProfile(String val) {
        getAppPreferences().edit().putString(APP_PREFERENCES_KEY, val).apply();
    }

    public static String getAppProfile() {
        return getAppPreferences().getString(APP_PREFERENCES_KEY, null);
    }

    public static void removeAppProfile() {
        getAppPreferences().edit().remove(APP_PREFERENCES_KEY).apply();
    }

    public static void clearAppPreferences() {
        getAppPreferences().edit().clear().apply();
    }

    public static void setAppFlag(String key, boolean flag) {
        getAppPreferences().edit().putBoolean(key, flag).apply();
    }

    public static boolean getAppFlag(String key) {
        return getAppPreferences().getBoolean(key, false);
    }
}
